<template>
	<view>
		<view class="content">
			<view class="chep">
				<text>{{datalist.plateNo}}</text>
			</view>
			<view class="lb">
				<view class="name">停车地点：</view>
				<view class="tex">{{datalist.parkName}}</view>
			</view>
			<view class="lb">
				<view class="name">停车时长：</view>
				<view class="tex">{{datalist.parkDuration}}</view>
			</view>
			<view class="lb">
				<view class="name">入场时间：</view>
				<view class="tex">{{datalist.entryTime}}</view>
			</view>
			<view class="lb">
				<view class="name">停车费总额：</view>
				<view class="tex" style="color: #FF0000;">{{datalist.totalAmount}}</view>
			</view>
		</view>
		<view class="content">
			<view class="lb" style="border-bottom: 1rpx solid #F9F9F9;padding: 30rpx 30rpx; color: #FF0000;">
				<view class="name">积分可抵扣：{{datalist.deductibleCredit}}</view>
				<view class="tex">{{datalist.deductibleAmount}}元</view>
			</view>
			<view class="lb" style="padding: 30rpx;">
				<view class="name">支付方式：</view>
				<view class="tex">积分兑换</view>
			</view>
		</view>
		<view class="btn" @click="CheckParking()">兑换</view>
		<u-popup v-model="show" mode="center" :border-radius="20">
			<view class="pop_conte">
				<view class="clone" @click="()=> show = false">
					<image src="https://img.shihhl.com/shequ/clone.png" mode="widthFix"></image>
				</view>
				<view class="logo">
					<image src="https://img.shihhl.com/shequ/tcz.png" mode="widthFix"></image>
				</view>
				<view class="msg">当前积分不足，无法抵扣停车费</view>
				<view class="tip">前往停车系统缴费</view>
				<view class="dh" @click="gouop()">立即前往</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import { userexchangeCoupon } from '@/core/api/index.js'
	export default{
		data(){
			return{
				datalist:{},
				show:false
			}
		},
		onLoad(r) {
			this.datalist = JSON.parse(decodeURIComponent(r.data))
			console.log(this.datalist)
		},
		methods:{
			gouop(){
				uni.navigateToMiniProgram({
				  appId: 'wxbe95c07ce55f4f43',
				  path: 'pages/index/index?carNo=' + this.datalist.plateNo,
				  success(res) {
				    // 打开成功
				  }
				})
			},
			async CheckParking(){
				console.log(11 , this.datalist.deductAll)
				if(this.datalist.deductAll && this.datalist.totalAmount == 0){
					uni.showModal({
						title: '提示',
						content: '30分钟内免费停车，可直接出库',
						success:  (res)=> {
							if (res.confirm) {
								console.log('用户点击确定');
								this.MaCay()
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					return
				}
				if(this.datalist.deductAll){
					uni.showModal({
					title: '积分抵扣停车费',
						content: '可用积分抵扣停车费，兑换后立即生效',
						success:  (res) =>{
							if (res.confirm) {
								console.log('用户点击确定');
								this.MaCay()
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					return
				}
				// console.log(data)
				this.MaCay()
			},
			async MaCay(){
				const data = await userexchangeCoupon(this.datalist.plateNo)
				this.$store.dispatch('user/getUserinfo')
				if(!this.datalist.deductAll){
					uni.showModal({
						title: '提示',
						content:`当前积分可抵扣${this.datalist.deductibleAmount}元。\r\n需前往停车系统缴费`,
						success: (res) =>{
							if (res.confirm) {
								this.show = true
							} else if (res.cancel) {
								console.log('用户点击取1消');
							}
						}
					});
					return
				}
				if(this.datalist.deductAll && data.code == '00000'){
					uni.redirectTo({
						url: '/pages/home/parkingrecord'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.content{
		margin: 20rpx 40rpx;
		background-color: #fff;
		.chep{
			padding: 35rpx 30rpx;
			margin-bottom: 15rpx;
			width: auto;
			border: 1rpx solid #F9F9F9;
			text{
				background: #EFF7FB;
				display: block;
				border-radius: 10rpx;
				padding: 1rpx 15rpx;
				    width: fit-content;
					font-size: 26rpx;
			}
		}
		.lb{
			display: flex;
			padding: 15rpx 30rpx;
			justify-content: space-between;
			.name{
				color: #A2A2A2;
			}
		}
	}
	.btn{
		background: #F26B2E;
		margin:  60rpx 40rpx;
		// width: 100%;
		height: 80rpx;
		color: #fff;
		font-size: 32rpx;
		text-align: center;
		line-height: 80rpx;
		border-radius: 60rpx;
	
	}
	.pop_conte{
		width: 80vw;
		height: 500rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		position: relative;
		.clone{
			width: 50rpx;
			height: 50rpx;
			position: absolute;
			    right: 5%;
			    top: 4%;
			image{
				width: 100%;
			}
		}
		.logo{
			width: 110rpx;
			image{
				width: 100%;
			}
		}
		.msg{
			font-size: 32rpx;
			margin: 10rpx 0 20rpx;
		}
		.tip{
			font-size: 40rpx;
			color: var(--Color, #F26B2E);
		}
		.dh{
			background: #F26B2E;
			height: 80rpx;
			color: #fff;
			font-size: 32rpx;
			text-align: center;
			line-height: 80rpx;
			margin: 50rpx 0 0;
			border-radius: 60rpx;
			width: 80%;
		}
	}
</style>